import { game } from "cc";
import protocol, { new_world } from "../../proto/protocol";

export namespace Utils {
    let serverNowMS: number = 0;
    let configs: protocol.new_world.v1.ConfigsResult = {} as protocol.new_world.v1.ConfigsResult
    export function setConfigs(config: protocol.new_world.v1.ConfigsResult) {
        configs = config
    }
    export function getConfigs() {
        return configs
    }
    export function randomInt(min: number, max: number) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }

    export function setServerTime(serverNowMS: number) {
        serverNowMS = serverNowMS - game.totalTime;
    }
    export function getServerTime() {
        if (serverNowMS == 0) {
            return new Date().getTime();
        }
        return serverNowMS + game.totalTime;
    }

    export function getlinggenStr(linggen: { [k: string]: protocol.new_world.shared.v1.IImmortalSkill }) {
        let str = ""
        let keys = Object.keys(linggen)
        for (let k of keys) {
            // linggen[k].skill_id
            let cfg = configs.ling_gen_configs.find(item => item.id == linggen[k].skill_id)
            if (cfg) {
                str += cfg.name + " "
            }
        }
        return str
    }
    export function getTezhiStr() {
        let str = ""
    }

    export function getQualityStr(quality: number) {
        let strArr = ["", "平庸", "出众", "卓绝", "天骄", "惊才艳艳"]
        return strArr[quality]
    }
    export function getLevelStr(level: number) {
        let bigRealmArr = ["煅体", "练气", "筑基", "金丹", "元婴", "化神", "返虚", "合体", "大乘", "渡劫"];
        let smallRealmArr = ["初入", "一重", "二重", "三重", "四重", "五重", "六重", "七重", "八重", "九重"];
        if (level % bigRealmArr.length == 0) {
            return smallRealmArr[level % smallRealmArr.length] + bigRealmArr[Math.floor(level / bigRealmArr.length)]
        } else {
            return bigRealmArr[Math.floor(level / bigRealmArr.length)] + smallRealmArr[level % smallRealmArr.length]
        }
    }
    export function getStatusStr(status: any) {
        let str = "活跃"
        switch (status) {
            case new_world.shared.v1.FishStatus.alive:
                str = "活跃"
                break;
            case new_world.shared.v1.FishStatus.sleep:
                str = "沉睡"
                break;
            case new_world.shared.v1.FishStatus.up_sell:
                str = "下架"
                break;
            case new_world.shared.v1.FishStatus.dead:
                str = "死亡"
                break;
            case new_world.shared.v1.FishStatus.refined:
                str = "已炼化"
                break;
            case new_world.shared.v1.FishStatus.godlike:
                str = "已飞升"
                break;
        }
        return str
    }
}